package com.monkey.core.domain.role;

import com.monkey.core.domain.BaseEntity;
import com.monkey.core.domain.permission.Permission;
import com.monkey.core.domain.resource.Menu;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;

/**
 * 此处没有使用关联 是为了提高性能（后续会挨着查询资源和权限列表，因为有缓存，数据量也不是很大 所以性能不会差）
 */
@Entity
@Table(name = "sys_role_resource_permission")
@DynamicUpdate
@DynamicInsert
public class RoleResourcePermission extends BaseEntity<Long> {

    public static final String DEFAULT_PERMISSIONS_SEPARATOR = ",";

    /**
     * 角色
     */
    @ManyToOne
    @JoinColumn(name = "role_id")
    private Role role;

    /**
     * 资源
     */
    @ManyToOne
    @JoinColumn(name = "resource_id")
    private Menu menu;

    @ManyToOne
    @JoinColumn(name = "permission_id")
    private Permission permission;

    @Transient
    private String actualIdentity;

    public RoleResourcePermission() {
    }

    public Role getRole() {
        return role;
    }

    public void setRole(Role role) {
        this.role = role;
    }

    public Permission getPermission() {
        return permission;
    }

    public void setPermission(Permission permission) {
        this.permission = permission;
    }

    public Menu getMenu() {
        return menu;
    }

    public void setMenu(Menu menu) {
        this.menu = menu;
    }

    public String getActualIdentity() {
        return actualIdentity;
    }

    public void setActualIdentity(String actualIdentity) {
        this.actualIdentity = actualIdentity;
    }
}
